/**
 * DataTable工具
 * @作者 田应平
 * @创建时间 2020-03-25 19:35
 * @QQ号码 444141300
 * @官网 http://www.fwtai.com
*/
;(function(){
  /*
      pageDataTable.buttons(thisTable);-> 显示全部;
      pageDataTable.buttons(thisTable,[]);->仅显示前2个;
      pageDataTable.buttons(thisTable,[3,4]);->显示全部;
      
      pageDataTable.action(thisTable);
      pageDataTable.select(thisTable,tableDom);
      pageDataTable.tooltip();
  */
  pageDataTable = {
    /*自定义显示工具条按钮,(thisTable,[])仅显示前2个;(thisTable)或(thisTable,[3,4])显示全部;*/
    buttons : function(dataTable,arrs){
      var buttons = [
        {
          "text" : "<i class='ace-icon glyphicon glyphicon-list bigger-110 blue' id='iconColumn'></i><span class='hidden'>自定义显示|隐藏列</span>",
          "className" : "btn btn-white btn-primary",
        },
        {
          "text" : "<i class='ace-icon glyphicon glyphicon-refresh bigger-110' id='iconRefresh'></i><span class='hidden'>刷新</span>",
          "className" : "btn btn-white btn-primary"
        },
        {
          "extend" : "csv",
          "text" : "<i class='fa fa-database bigger-110 orange'></i><span class='hidden'>导出CSV文件</span>",
          "className": "btn btn-white btn-primary"
        },
        {
          "extend" : "print",
          "text" : "<i class='fa fa-print bigger-110 grey'></i><span class='hidden'>打印</span>",
          "className" : "btn btn-white btn-primary",
          "autoPrint" : false,
          "message" : '用打印机打印当前页面'
        }
      ];
      if(arrs){
        buttons = [
          {
            "text" : "<i class='ace-icon glyphicon glyphicon-list bigger-110 blue' id='iconColumn'></i><span class='hidden'>自定义显示|隐藏列</span>",
            "className" : "btn btn-white btn-primary",
          },
          {
            "text" : "<i class='ace-icon glyphicon glyphicon-refresh bigger-110' id='iconRefresh'></i><span class='hidden'>刷新</span>",
            "className" : "btn btn-white btn-primary"
          }
        ];
        arrs.forEach(value=>{
          switch (value){
            case 3:
              buttons.push({
                "extend" : "csv",
                "text" : "<i class='fa fa-database bigger-110 orange'></i><span class='hidden'>导出CSV文件</span>",
                "className": "btn btn-white btn-primary"
              })
              break;
            case 4:
              buttons.push({
                "extend" : "print",
                "text" : "<i class='fa fa-print bigger-110 grey'></i><span class='hidden'>打印</span>",
                "className" : "btn btn-white btn-primary",
                "autoPrint" : false,
                "message" : '用打印机打印当前页面'
              })
              break;
            default:
              break;
          }
        });
      }
      new $.fn.dataTable.Buttons(dataTable,{
        buttons : buttons
      });
      dataTable.buttons().container().appendTo($('.tableTools-container'));
    },
    //pageDataTable.action(dataTable);
    action : function(dataTable){
      var defaultCopyAction = dataTable.button(1).action();
      dataTable.button(1).action(function (e, dt, button, config){
        try{
          defaultCopyAction(e, dt, button, config);
        }catch(e){}
        $('.dt-button-info').addClass('gritter-item-wrapper gritter-info gritter-center white');
      });
      //表格右上角的按钮组
      var defaultColvisAction = dataTable.button(0).action();
      dataTable.button(0).action(function (e, dt, button, config){
        try{
          defaultColvisAction(e, dt, button, config);
        }catch(e){}
        if($('.dt-button-collection > .dropdown-menu').length == 0) {
          $('.dt-button-collection')
            .wrapInner('<ul class="dropdown-menu dropdown-light dropdown-caret dropdown-caret" />')
            .find('a').attr('href','javascript:;').wrap("<li />");
        }
        $('.dt-button-collection').appendTo('.tableTools-container .dt-buttons');
      });
      setTimeout(function() {
        $($('.tableTools-container')).find('a.dt-button').each(function(objIndex){
          /*if(objIndex != 0){
            $(this).css("border-left","none");//处理表格右上角的按钮组的左边框的样式
          }*/
          var div = $(this).find(' > div').first();
          if(div.length == 1) div.tooltip({container: 'body', title: div.parent().text()});
          else $(this).tooltip({container: 'body', title: $(this).text()});
        });
      }, 500);
    },
    //pageDataTable.select(dataTable,'#dynamic-table');
    select : function(dataTable,tableDom){
      /*选择*/
      dataTable.on('select', function ( e, dt, type, index ) {
        if ( type === 'row' ) {
          $(dataTable.row(index).node()).find('td:eq(0) input:checkbox').prop('checked', true);
        }
      });

      /*取消选择*/
      dataTable.on('deselect', function ( e, dt, type, index ) {
        if ( type === 'row' ) {
          $(dataTable.row(index).node()).find('td:eq(0) input:checkbox').prop('checked', false);
        }
      });

      //(基于表头的复选框的选择/取消选择而全选选择或全部取消选择)select/deselect all rows according to table header checkbox
      $(tableDom +' > thead > tr > th input[type=checkbox], '+tableDom+'_wrapper input[type=checkbox]').eq(0).on('click', function(){
        var th_checked = this.checked;
        $(tableDom).find('tbody > tr').each(function(){
          var row = this;
          if(th_checked) dataTable.row(row).select();
          else  dataTable.row(row).deselect();
        });
      });

      //(基于每一行的第一列的选择/取消选择而该行被选择或取消选择,留着) a row when the checkbox is checked/unchecked
      /*$(tableDom).on('click', 'td:eq(0) input[type=checkbox]' , function(){
          var row = $(this).closest('tr').get(0);
          if(!this.checked) dataTable.row(row).deselect();
          else dataTable.row(row).select();
      });*/

      /*点击后显示更多???*/
      /*$(document).on('click',tableDom+'.dropdown-toggle', function(e) {
          e.stopImmediatePropagation();
          e.stopPropagation();
          e.preventDefault();
      });*/
    },
    // pageDataTable.tooltip();
    tooltip : function(){
      $('[data-rel="tooltip"]').tooltip(
        {
          placement : function(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table');
            var off1 = $parent.offset();
            var w1 = $parent.width();
            var off2 = $source.offset();
            if(parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
            return 'left';
          }
        }
      );
    },
    //iDisplayLength : pageDataTable.iDisplayLength,
    iDisplayLength : 20,
    //aLengthMenu : pageDataTable.aLengthMenu,
    aLengthMenu : [20,50,99],
    /*用法:var thisTable = pageDataTable.initDataTable({tableDom:'#table',sAjaxSource:url,fnServerParams : function(params){}});*/
    initDataTable : function(options){// api http://datatables.club/manual/api.html
      var tableDom = (options.tableDom) ? options.tableDom : '#';//必填
      var dom = (options.dom) ? options.dom : "t<'row'<'col-sm-2 hidden-480'l><'col-sm-3 hidden-480'i><'col-sm-7'p>>";//t分页条显示的位置;row单独一行;l每页大小的选项;i显示N到M的数据;p分页条;<>里的配置class的,当然在调用时配置成 dom : "t<'row'<'col-sm-6'i><'col-sm-6'p>>",此时仅显示的是 i显示N到M数据和分页条;
      var scrollX = (options.scrollX) ? options.scrollX : '100%';//用于设置横向滚动
      var scrollY = (options.scrollY) ? options.scrollY : '';//用于设置垂直滚动
      var iDisplayLength = (options.iDisplayLength) ? options.iDisplayLength : pageDataTable.iDisplayLength;
      var aLengthMenu = (options.aLengthMenu) ? options.aLengthMenu : pageDataTable.aLengthMenu;
      var bStateSave = (options.bStateSave) ? options.bStateSave : false;//加载记忆页码
      var sAjaxSource = (options.sAjaxSource) ? options.sAjaxSource : '';//必填
      var fnServerParams = (options.fnServerParams) ? options.fnServerParams:null;//必填
      var aoColumns = (options.aoColumns) ? options.aoColumns:[];//必填
      var columnDefs = (options.columnDefs) ? options.columnDefs:[];//必填
      var complete = (options.complete) ? options.complete:null;//表格显示完毕后的回调,用于弹窗之类的,可参考项目 law-frontend/src/main/resources/static/smsRecord.html
      var rowCallback = (options.rowCallback) ? options.rowCallback:null;//可用统计
      var drawCallback = (options.drawCallback) ? options.drawCallback:null;//自定义行的复杂样式,每次绘制表格都执行
      var footer = (options.footer) ? options.footer:null;//可用统计
      var selectedChange = options.selected;//已选择回调事件,下面要验证是否有该选项
      $(window).resize(function(){
        $.fn.dataTable.tables({visible:true,api:true}).columns.adjust();
      });
      return $(tableDom).DataTable({
        scrollX : scrollX,
        scrollY: scrollY, // 开启垂直滚动条
        scrollCollapse: true, // 当表格数据不足时，自动缩小表格高度
        dom : dom,
        bAutoWidth : false,
        aaSorting : [],
        iDisplayLength : iDisplayLength,
        aLengthMenu : aLengthMenu,
        bServerSide : true,
        serverSide : true,
        bDeferRender : true,
        select : {
          style : 'multi',
          //selector : 'td:first-child'//指定选择器,即指定哪一个列或哪一个元素作为该行的选中或取消选中
          selector : 'td:first-child input'
        },
        searching : false,
        destroy : true,
        bSortMulti : false,
        bStateSave : bStateSave,
        fnServerData : winFn.dataTableData,//此处是 function (url,params,callback,oSettings){},//oSettings是各个参数,但已封装集成在一块了,方便维护管理
        sAjaxSource : sAjaxSource,
        fnServerParams : function(params){
          if(fnServerParams != null){
            fnServerParams(params);
          }
        },
        aoColumns : aoColumns,
        columnDefs : columnDefs,
        /*每一行创建完调用的函数*/
        createdRow : function (tr,data,index){
          // row : tr dom
          // data: row data
          // dataIndex:row data's index
          /*if (index === 1){
              $(row).css({"background":"#81adee"});
          }
          if (index === 2){
              $(row).addClass('selected');
              $(row).find('td:eq(0) input[type=checkbox]').prop("checked",true);
          }*/
          //console.info(row);
          //console.info(data);
          //console.info(index);
          //$(row).find("td:eq(0)").css({"cursor":"pointer"}).attr("title","选择|取消");//好使,显示第1列为手型的鼠标形状
          var _input_ = $(tr).find("td:eq(0)").find('input[type=checkbox]');
          if(_input_.length > 0){
            $(tr).find("td:eq(0)").attr("title","选择|取消");//好使,显示第1列为手型的鼠标形状
            $(tr).find("td:eq(0) input[type=checkbox]").attr("class","ace");
          }
        },
        /*每一行被创建，但还没有被加载到document中，这个函数优先于createdRow,个人觉得用createdRow更好*/
        rowCallback : function (row,data,index) {
          // row : tr dom
          // data: row data
          // index:row data's index
          /*if(index === 3){
              $('td:eq(2)',row).html('<b>已被rowCallback方法更改了内容</b>');
          }*/
          if(rowCallback){
            rowCallback(row,data,index)
          }
        },
        /*thead被描画后调用*/
        headerCallback : function (thead, data, start, end, display) {
          //thead:dom， data:原始的datatable数据，display：当前显示排序好的datatable数据（有可能经过排序）
          // start end ：当前dispaly数据的开始结束序号
          //$(thead).find('th').eq(0).html( 'Displaying '+(end-start)+' records');
          //console.info(thead);//输出结果:<tr role="row">
          //console.info(data);//输出结果:是后端返回的原始数据
          //console.info(start);//输出结果:0
          //console.info(end);//输出结果:4]
          //console.info(display);//输出结果:[0,1,2,3,4]
          //$(thead).find('th').css("background","red");//表头样式
          var len = $(thead).find('th').length;
          $(thead).find('th').eq(len-1).css({"border-right":"1px solid #d5d5d5"});
          $($(thead).find('th')).each(function(index,th){
            if(index != 0 && index < len-1){
              $(th).attr("title",$(th).text());
            }
          });
        },
        /*tfoot被描画后调用，通常可用于计算合计值*/
        footerCallback : function (tfoot, data, start, end, display) {
          //tfoot:dom， data:原始的datatable数据，display：当前显示排序好的datatable数据（有可能经过排序）
          //start end ：当前dispaly数据的开始结束序号
          //var api = this.api();
          //console.info(this);//输出结果:table dom
          //console.info(api.column(2));//输出结果:Object[[2]],这个是数组,表示所有行的第3列
          //console.info(api.column(2).data());//输出结果:Object["main", "parent_sys_setting", "sys_menu", "sys_user", "sys_role"],这个是数组，表示所有行的第3行依次从上到下的值
          //console.info(api.column(3).data());//输出结果:Object[1, 1, 2, 2, 2],这个是数组表示第1行的第列的值是1;
          //$(api.column(3).footer()).html(api.column(3).data().reduce(function(a,b){},0));//表示看不懂
          var items = JSON.parse(sessionStorage.getItem("btnRows"));
          setTimeout(function(){
            $.each(items,function(index,item){
              var value = item.permission;
              $("[permission='"+value+"']").css({"display":""});//inline
              var exist = $('#'+value).attr('id');
              if(exist){
                $('#' + value).val('1');//有值就有权限
              }
            });
            var display = $("[permission]");
            $.each(display,function(index,value){
              var css = $(this).css("display");
              if(css == 'none'){
                $(this).remove();
              }else{
                var style = $(this).attr("style");
                if(style == ''){
                  $(this).removeAttr("style");//移除style属性
                }
                $(this).removeAttr("permission");
              }
            });
            if(footer){
              footer(data,start,end,$(tableDom+' tr:first').find('th').length);//表头的长度
            }
          },32);//可能会有问题
        },
        /*操作dom应放在initComplete操作???,可以在此操作判断后端返回的数据值是否显示列,https://www.cnblogs.com/daixinyu/p/6866516.html*/
        fnInitComplete : function(settings,data){
          //$("table"+tableDom+" tbody tr").find("td:eq(0)").css({"cursor":"pointer"});
          var columnData = sessionStorage.getItem(tableDom.substring(1));//获取之前已保存的自定义显示列
          if(columnData){
            setTimeout(()=> {
              var columnLen = sessionStorage.getItem(tableDom.substring(1) + 'Len');//获取之前已保存列长度
              var api = $(tableDom).DataTable();
              var headRow = JSON.parse(columnData);
              for(var c = 0; c < columnLen; c++){
                var visible = headRow[c];
                if(!visible){
                  api.column(c).visible(visible, visible);
                }
              }
              $.fn.dataTable.tables({visible:true,api:true}).columns.adjust();
            },40);
          }
          if(AppKey.code.code200 == data.code){
            setTimeout(()=>{
              var lastCol = settings.oAjaxData.iColumns-1;
              var obj = $("table"+tableDom+" tbody tr").find("td:eq("+lastCol+")").text();
              if(obj == ''){
                $(tableDom).DataTable().column(lastCol).visible(false,false);//隐藏多列，使用redrawCalculations来提高性能
              }
              $.fn.dataTable.tables({visible:true,api:true}).columns.adjust();
            },35);
          }
          if(complete){
            complete(settings,data);
          }
          //监听表头是否已勾选全选的那个复选框
          $(tableDom+"_wrapper .dataTables_scroll .dataTables_scrollHead table thead tr th:eq(0) label input[type='checkbox']").on("change",function(event){
            if(selectedChange){
              selectedChange($(this).prop("checked"));
            }
          });
        },
        fnDrawCallback : function(settings){
          winFn.dropdownIcon();
          var lastCol = settings.oAjaxData.iColumns-1;
          $("table"+tableDom+" tbody tr").each(function(){
            $(this).find('td').each(function(idx,item){
              var title = $(this).text();
              if(title != ''){
                if(lastCol != idx){
                  this.setAttribute('title',title);
                }
              }
            });
          });
          //处理表格中若全选了则表格字段选中,否则取消选中--开始
          /**去重*/
          function handlerRepetition(arrays){
            var tempArrs = [];
            for(var i = 0; i < arrays.length; i++){
              if(tempArrs.indexOf(arrays[i]) == -1){
                tempArrs.push(arrays[i]);
              }
            }
            return tempArrs;
          }
          /**控制是否选中表头的复选框*/
          function handlerProp(checked){
            $(tableDom+"_wrapper .dataTables_scroll .dataTables_scrollHead table thead tr th:eq(0) label input[type='checkbox']").prop("checked",checked);
          }
          /**处理是否需要勾选表头的复选框的前置逻辑*/
          function handlerHead(){
            var checkboxArrs = [];
            var isTotal = 0;
            $(tableDom + ' tbody tr').each(function(item){
              var _selected = $(this).children('td:eq(0)').find('input[type="checkbox"]').prop("checked");
              isTotal++;
              if(_selected){
                checkboxArrs.push(_selected);
              }
            });
            handlerProp(isTotal == checkboxArrs.length);
          }
          //处理表格中若全选了则表格字段选中,否则取消选中--结束
          //处理是否已选中数据表格的表体的列表行--开始
          /**处理表格中的表体的行是否已选中*/
          function handlerTbody(){
            var checkboxArrs = [];
            $(tableDom + ' tbody tr').each(function(item){
              var _selected = $(this).children('td:eq(0)').find('input[type="checkbox"]').prop("checked");
              if(_selected){
                checkboxArrs.push(_selected);
              }
            });
            checkboxArrs = handlerRepetition(checkboxArrs);
            selectedChange(checkboxArrs.length > 0);//是否有已勾选的
          }
          //处理是否已选中数据表格的表体的列表行--结束
          $(tableDom + ' tbody tr').each(function(item){
            $(this).children('td:eq(0)').find('input[type="checkbox"]').on("change",function(event){
              handlerHead();
              if(selectedChange){//仅存在时才触发
                handlerTbody();
              }
            });
          });
          if(drawCallback){
            drawCallback(settings);//表头的长度
          }
        }
      });
    },
    /*用法:pageDataTable.columnCustom(thisTable,tableDom,'#divKeyColumns');*/
    columnCustom : function(thisTable,tableDom,divDom){
      var thisApi = $(tableDom).DataTable();
      var header = thisTable.columns().header();//api用法
      var headerLen = header.length;
      var columnLen =  headerLen - 1;
      var startColumn = header[0].innerText.length > 0;//第1列是否是复选框,大于0说明不是复选框
      var opts = header[columnLen].innerText == '操作选项';//最后1行是否是‘操作选项’
      var start = startColumn ? 0 : 1;//若第1列不是复选框则从0开始,否则1开始
      var len = startColumn ? (opts ? (columnLen) : (headerLen)) : (columnLen);
      var localColumnData = tableDom.substring(1);//有两个地方调用到:1是生成input[type=checkbox]时,2是当已保存后再此读取时赋值给input[type=checkbox]是否显示列
      var columnData = sessionStorage.getItem(localColumnData);
      var html = "<table class='table table-striped table-bordered table-hover no-margin-bottom no-border-top'>";
      html += "<thead>";
      html += "<tr>";
      html += "<th width='40' class='center'>";
      html += "<i class='ace-icon glyphicon glyphicon-list bigger-110'></i>";
      html += "</th>";
      html += "<th>表头名称</th>";
      html += "<th width='40' class='center'>";
      html += "<i class='ace-icon fa fa-eye green bigger-110'></i>";
      html += "</th>";
      html += "</tr>";
      html += "</thead>";
      html += "<tbody>";
      for(var i = start; i < len; i++){
        html += "<tr>";
        html += "<td class='center'>";
        var indexLabel = startColumn ? (i+1) : i;
        html += "<label>"+indexLabel+"</label>";
        html += "</td>";
        html += "<td>"+header[i].innerText+"</td>";
        html += "<td class='center'>";
        html += "<input type='checkbox' id='"+(localColumnData+i)+"'/><label style='margin:0px;'></label>";
        html += "</td>";
        html += "</tr>";
      }
      html += "</tbody>";
      html += "</table>";
      $(divDom).html(html);
      if(columnData){
        var kv = JSON.parse(columnData);
        $.each(kv,function(k,v){
          $('#'+(localColumnData+k)).prop("checked",v);
        });
      }else{
        for(var i = start; i < len;i++){
          var check = thisApi.column(i).visible();
          $('#'+(localColumnData+i)).prop("checked",check);
        }
      }
      $(divDom).hcheckbox();//初始化样式
      layerFn.addOrEdit('选择自定义显示隐藏列',divDom,['500px','430px'],function(index,layero){
        var json = {};
        for(var i = start; i < len; i++){
          var checked = $('#'+localColumnData+i).prop("checked");
          json[i] = checked;
          thisApi.column(i).visible(checked,checked);
        }
        $.fn.dataTable.tables({visible:true,api:true}).columns.adjust();
        layerFn.closeIndex(index);
        if(!sessionStorage){
          layerFn.alert('不支持sessionStorage,操作失败',AppKey.code.code199);
        }else{
          var clear = true;
          for(t in json){
            if(!json[t]){
              clear = false;
            }
          }
          if(clear){//全选时清空
            sessionStorage.removeItem(localColumnData);
            sessionStorage.removeItem(localColumnData+'Len');
          }else{
            sessionStorage.setItem(localColumnData,JSON.stringify(json));//保存的自定义显示列
            sessionStorage.setItem(localColumnData+'Len',headerLen);//保存的列长度
          }
        }
      });
    },
    //多于length个字符才显示省略号;注意需要在 方法 formatColumn 的前面执行
    columnEllipsis : function(value,length){
      value = typeof value === 'string' ? value.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') : value;
      if(value){
        if (value.length > length){
          return "<span title='"+value+"'>"+value.substring(0,length) +"<a style='outline:none;text-decoration: none;' href='javascript:;' title='查看' onclick='javascript:layerFn.alert(\""+value+"\")'>…</a></span>";
        }else{
          return "<span title='"+value+"'>"+value+"</span>";
        }
      }else{
        return "";
      }
    },
    formatColumn : function(value){
      if(value == undefined || value == '') return "";
      value = typeof value === 'string' ? value.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') : value;
      var width = winFn.fnGetWidth();
      switch (width){
        case 1280:
          if(value){
            if (value.length > 24){
              return "<span title='"+value+"'>"+value.substring(0,24) +"<a style='outline:none;text-decoration: none;' href='javascript:;' title='查看' onclick='javascript:layerFn.alert(\""+value+"\")'>…</a></span>";
            }else{
              return "<span title='"+value+"'>"+value+"</span>";
            }
          }else{
            return "";
          }
        case 1360:
        case 1366:
          if(value){
            if (value.length > 32){
              return "<span title='"+value+"'>"+value.substring(0,32) +"<a style='outline:none;text-decoration: none;' href='javascript:;' title='查看' onclick='javascript:layerFn.alert(\""+value+"\")'>…</a></span>";
            }else{
              return "<span title='"+value+"'>"+value+"</span>";
            }
          }else{
            return "";
          }
        case 1440:
          if(value){
            if (value.length > 38){
              return "<span title='"+value+"'>"+value.substring(0,38) +"<a style='outline:none;text-decoration: none;' href='javascript:;' title='查看' onclick='javascript:layerFn.alert(\""+value+"\")'>…</a></span>";
            }else{
              return "<span title='"+value+"'>"+value+"</span>";
            }
          }else{
            return "";
          }
        case 1600:
          if(value){
            if (value.length > 42){
              return "<span title='"+value+"'>"+value.substring(0,42) +"<a style='outline:none;text-decoration: none;' href='javascript:;' title='查看' onclick='javascript:layerFn.alert(\""+value+"\")'>…</a></span>";
            }else{
              return "<span title='"+value+"'>"+value+"</span>";
            }
          }else{
            return "";
          }
        case 1920:
          if(value){
            if (value.length > 46){
              return "<span title='"+value+"'>"+value.substring(0,46) +"<a style='outline:none;text-decoration: none;' href='javascript:;' title='查看' onclick='javascript:layerFn.alert(\""+value+"\")'>…</a></span>";
            }else{
              return "<span title='"+value+"'>"+value+"</span>";
            }
          }else{
            return "";
          }
        case 2560:
          if(value){
            if (value.length > 60){
              return "<span title='"+value+"'>"+value.substring(0,60) +"<a style='outline:none;text-decoration: none;' href='javascript:;' title='查看' onclick='javascript:layerFn.alert(\""+value+"\")'>…</a></span>";
            }else{
              return "<span title='"+value+"'>"+value+"</span>";
            }
          }else{
            return "";
          }
        default:
          if(value){
            return "<span title='"+value+"'>"+value+"</span>";
          }else{
            return "";
          }
      }
    }
  };
})(jQuery);